{extend name='public/list'/}
{block name='fields'}
<div class="layui-inline">
    <label class="layui-form-label">键</label>
    <div class="layui-input-block">
        <input type="text" name="meta_key" value="" placeholder="请输入键" class="layui-input">
    </div>
</div>
<div class="layui-inline">
    <label class="layui-form-label">值</label>
    <div class="layui-input-block">
        <input type="text" name="meta_value" value="" placeholder="请输入值" class="layui-input">
    </div>
</div>
{/block}
{block name='js'}
<script>
    var cols = [
        [{
            checkbox: true,
            fixed: 'left',
        }, {
            field: 'id',
            title: 'ID',
            sort: true,
            width: 80,
        }, {
            field: 'meta_key',
            title: '键',
            edit: false,
        }, {
            field: 'meta_value',
            title: '值（可修改）',
            edit: 'text',
        }, {
            field: 'status',
            title: '状态',
            sort: true,
            width: 95,
            templet: function (res) {
                return '<input type="checkbox" name="status" lay-filter="status" value="' + res.id + '" lay-skin="switch" lay-text="启用|禁用"' + (res.status == 0 ? ' checked' : '') + '>';
            }
        }, {
            field: 'time',
            title: '时间',
            sort: true,
        }, {
            title: '操作',
            align: 'center',
            width: 120,
            toolbar: '#databar'
        }]
    ];

    // 列表开关事件
    layui.use(['form', 'table'], function () {
        var form = layui.form
            , table = layui.table
            , $ = layui.jquery;

        // 获取应用、控制器和方法
        var module = '{:app("http")->getName()}'
            , controller = '{$Request.controller}'
            , action = '{$Request.action}';

        form.on('switch(status)', function (obj) {
            $.post('/'+ module +'/'+ controller +'/save_edit', { id: this.value, status: obj.elem.checked ? 0 : 1 }, function (res) {
                if (res.code) {
                    layer.alert(res.msg, { icon: 2 });
                    setTimeout(function () {
                        table.reload('dataTable');
                        layer.close();
                    }, 1000);
                    return;
                }
                layer.msg(res.msg);
            }, 'json');
        });
        return false;
    });
</script>
{/block}